const ERROR = false; //错误
const SUCCESS = true; // 成功
export const RULE_MAP = {
    require: (val) => {
        if (
            (val !== 0 && !val) ||
            val === null ||
            val == undefined ||
            (Array.isArray(val) && val.length === 0)
        ) {
            return ERROR
        }
        return SUCCESS;
    },
    number: (val) => {
        if (typeof val !== 'number' || isNaN(Number(val))) {
            return ERROR
        }
        return SUCCESS;
    },
    phone: (val) => {
        if (!(/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(val))) {
            return ERROR
        }
        return SUCCESS;
    },
    string: (val) => {
        if (typeof val !== 'string') {
            return ERROR
        }
        return SUCCESS;
    },
    abs: (val) => {
        if (val < 0) {
            return ERROR
        }
        return SUCCESS;
    },
    same: (val, { val_2 }) => {
        if (val !== val_2) return ERROR
        return SUCCESS;
    },
    max: (val, { max }) => {
        if (val > max) return ERROR
        return SUCCESS;
    },
    min: (val, { min }) => {
        if (val < min) return ERROR
        return SUCCESS;
    },
    range: (val, { min, max }) => {
        if ((val < min) || (val > max)) {
            return ERROR
        }
        return SUCCESS;
    }
}